package vip.specimen.system.datasource.validation.implement;

import org.apache.shiro.SecurityUtils;
import vip.specimen.system.datasource.entity.SystemUserEntity;
import vip.specimen.system.datasource.validation.annotation.AdminDrop;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.validation.ConstraintValidator;
import javax.validation.ConstraintValidatorContext;

/**
 * *@Author: 余浪人
 * *@Date：2021/4/6 16:23
 * *@Email:yulangren520@Gmail.com
 * *@QQ:1368419640
 **/
public class AdminDropImp implements ConstraintValidator<AdminDrop, Boolean> {
    @Resource
    private HttpServletRequest request;

    @Override
    public boolean isValid(Boolean aBoolean, ConstraintValidatorContext constraintValidatorContext) {
        SystemUserEntity user = (SystemUserEntity) SecurityUtils.getSubject().getPrincipal();
        if ((null != user && !user.getUuid().toString().equals(request.getParameter("uuid"))) || (null != user && user.isAdmin() == aBoolean)) return true;
        return false;
    }
}
